package cn.itrip.controller;

import cn.itrip.bean.ItripHotelVO;
import cn.itrip.common.DtoUtil;
import cn.itrip.common.EmptyUtils;
import cn.itrip.common.Page;
import cn.itrip.dto.Dto;
import cn.itrip.service.SearchService;
import cn.itrip.vo.hotel.SearchHotCityVO;
import cn.itrip.vo.hotel.SearchHotelVO;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController  //Controller+responseBody
@RequestMapping(value = "/api/hotellist")
@Api(value = "search测试",tags = "{search测试}")
public class HotelListController {

    @Resource
    private SearchService searchService;
    @RequestMapping(value = "/searchItripHotelListByHotCity", method = RequestMethod.POST, produces = "application/json")
    public Dto<List<ItripHotelVO>> searchItripHotelListByHotCity(@RequestBody SearchHotCityVO cityVO){
        try {
            //判断目的地是否未空
            if(!EmptyUtils.isNotEmpty(cityVO.getCityId())){
                return DtoUtil.returnFail("城市id不能为空 ", "20004");
            }
            List<ItripHotelVO> itripHotelVOS = searchService.searchSearchHotCityVO(cityVO);
            return DtoUtil.returnDataSuccess(itripHotelVOS);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "20003");
        }
    }


    /**
     * 酒店分页查询
     * @param vo
     * @return
     */
    @ApiOperation(value = "查询酒店分页")
    @RequestMapping(value = "/searchItripHotelPage", method = RequestMethod.POST, produces = "application/json")
    public Dto<Page<ItripHotelVO>> searchItripHotelPage(@RequestBody SearchHotelVO vo){
        try {
            //判断目的地是否未空
            if(!EmptyUtils.isNotEmpty(vo.getDestination())){
                return DtoUtil.returnFail("目的地不能为空", "20004");
            }
            Page page=searchService.searchItripHotelPage(vo);
            return DtoUtil.returnDataSuccess(page);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "20003");
        }
    }

}
